package com.ebt.m.customer.constant;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * 业务字典
 * Created by archer.qi on 2016/12/15.
 */
public class Dictionary {

    /* 缴费方式*/
    public static ArrayList<String> PAY_PERIOD_LIST = new ArrayList<>();
    public static HashMap<String, Integer> PAY_PERIOD_MAP = new HashMap<>();
    /* 保单状态*/
    public static HashMap<String, Integer> POLICY_STATUS_MAP = new HashMap<>();
    /* 职业类别*/
    public static ArrayList<String> CAREER_LEVEL_LIST = new ArrayList<>();
    public static HashMap<String, Integer> CAREER_LEVEL_MAP = new HashMap<>();
    /* 关系*/
    public static ArrayList<String> RELATION_LIST = new ArrayList<>();
    public static HashMap<String, Integer> RELATION_MAP = new HashMap<>();

    public static final int MAX_AGE = 120;
    public static final int APPLICANT_MIN_AGE = 18;
    public static final int INSURED_MIN_AGE = 0;
    public static ArrayList<String> APPLICANT_AGE_LIST = new ArrayList<>();
    public static ArrayList<String> INSURED_AGE_LIST = new ArrayList<>();

    static {
        PAY_PERIOD_LIST.add("趸交");
        PAY_PERIOD_LIST.add("年交");
        PAY_PERIOD_LIST.add("半年交");
        PAY_PERIOD_LIST.add("季交");
        PAY_PERIOD_LIST.add("月交");

        PAY_PERIOD_MAP.put("趸交", 0);
        PAY_PERIOD_MAP.put("年交", 1);
        PAY_PERIOD_MAP.put("半年交", 2);
        PAY_PERIOD_MAP.put("季交", 3);
        PAY_PERIOD_MAP.put("月交", 4);

        POLICY_STATUS_MAP.put("预收件", 0);
        POLICY_STATUS_MAP.put("承保件", 1);
        POLICY_STATUS_MAP.put("契撤件", 2);
        POLICY_STATUS_MAP.put("停效件", 3);
        POLICY_STATUS_MAP.put("失效件", 4);
        POLICY_STATUS_MAP.put("解约件", 5);
        POLICY_STATUS_MAP.put("终止件", 6);

        CAREER_LEVEL_LIST.add("一类");
        CAREER_LEVEL_LIST.add("二类");
        CAREER_LEVEL_LIST.add("三类");
        CAREER_LEVEL_LIST.add("四类");
        CAREER_LEVEL_LIST.add("五类");
        CAREER_LEVEL_LIST.add("六类");

        CAREER_LEVEL_MAP.put("一类", 1);
        CAREER_LEVEL_MAP.put("二类", 2);
        CAREER_LEVEL_MAP.put("三类", 3);
        CAREER_LEVEL_MAP.put("四类", 4);
        CAREER_LEVEL_MAP.put("五类", 5);
        CAREER_LEVEL_MAP.put("六类", 6);

        RELATION_LIST.add("请选择");
        RELATION_LIST.add("本人");
        RELATION_LIST.add("夫妻");
        RELATION_LIST.add("子女");
        RELATION_LIST.add("父母");
        RELATION_LIST.add("祖父母");
        RELATION_LIST.add("孙子女");
        RELATION_LIST.add("其他");

        RELATION_MAP.put("请选择", -1);
        RELATION_MAP.put("本人", 0);
        RELATION_MAP.put("夫妻", 1);
        RELATION_MAP.put("子女", 2);
        RELATION_MAP.put("父母", 3);
        RELATION_MAP.put("祖父母", 4);
        RELATION_MAP.put("孙子女", 5);
        RELATION_MAP.put("其他", 6);

        for (int i = APPLICANT_MIN_AGE; i <= MAX_AGE; i++) {
            APPLICANT_AGE_LIST.add(i + "岁");
        }

        for (int i = INSURED_MIN_AGE; i <= MAX_AGE; i++) {
            INSURED_AGE_LIST.add(i + "岁");
        }

    }


    public static class DictionaryUtils {

        /**
         * 根据职业名称获取代码
         *
         * @param name
         * @return
         */
        public static int getCareerCodeByName(String name) {
            if (TextUtils.isEmpty(name)) {
                return -1;
            }
            for (Map.Entry<String, Integer> career : CAREER_LEVEL_MAP.entrySet()) {
                if (career != null && name.equals(career.getKey())) {
                    return career.getValue();
                }
            }
            return -1;
        }

        /**
         * 根据职业代码获取名称
         *
         * @param code
         * @return
         */
        public static String getCareerNameByCode(int code) {
            for (Map.Entry<String, Integer> career : CAREER_LEVEL_MAP.entrySet()) {
                if (career != null && code == career.getValue()) {
                    return career.getKey();
                }
            }
            return null;
        }

        /**
         * 根据关系名称获取代码
         *
         * @param name
         * @return
         */
        public static int getRelationCodeByName(String name) {
            if (TextUtils.isEmpty(name)) {
                return -1;
            }
            for (Map.Entry<String, Integer> relation : RELATION_MAP.entrySet()) {
                if (relation != null && name.equals(relation.getKey())) {
                    return relation.getValue();
                }
            }
            return -1;
        }

        /**
         * 根据职业名称获取代码
         *
         * @param code
         * @return
         */
        public static String getRelationNameByCode(int code) {
            for (Map.Entry<String, Integer> career : RELATION_MAP.entrySet()) {
                if (career != null && code == career.getValue()) {
                    return career.getKey();
                }
            }
            return null;
        }

    }

}
